package com.holyn.guofang.viewcommon.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.holyn.guofang.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Holyn on 2017/6/8.
 */

public class UpdateRemarkDialog extends Dialog {
    private Context context;

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.et_input)
    TextView etInput;
    @BindView(R.id.tv_sure)
    TextView tvSure;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;
    @BindView(R.id.tv_line)
    TextView tvLine;

    private OnSureClickListener onSureClickListener = null;

    public interface OnSureClickListener{
        public void onSureClick(String value);
    }

    public UpdateRemarkDialog(@NonNull Context context) {
        super(context, com.holyn.mylibrary.R.style.custom_dialog);
        this.context = context;
        initView();
    }

    public UpdateRemarkDialog(@NonNull Context context, OnSureClickListener onSureClickListener) {
        super(context, com.holyn.mylibrary.R.style.custom_dialog);
        this.context = context;
        initView();
        this.onSureClickListener = onSureClickListener;
    }

    private void initView() {
        View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_update_remark, null);
        setContentView(dialogView);
        ButterKnife.bind(this);
        setCanceledOnTouchOutside(false);
    }

    public OnSureClickListener getOnSureClickListener() {
        return onSureClickListener;
    }

    public void setOnSureClickListener(OnSureClickListener onSureClickListener) {
        this.onSureClickListener = onSureClickListener;
    }

    @OnClick({R.id.tv_sure, R.id.tv_cancel})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_sure:
                if (onSureClickListener != null) {
                    String value = etInput.getText().toString().trim();
                    if (TextUtils.isEmpty(value)){
                        Toast.makeText(context, "请输入别名", Toast.LENGTH_SHORT).show();
                    } else {
                        onSureClickListener.onSureClick(value);
                    }
                } else {
                    UpdateRemarkDialog.this.dismiss();
                }
                break;
            case R.id.tv_cancel:
                UpdateRemarkDialog.this.dismiss();
                break;
        }
    }
}
